﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" Codebehind="UpdateCouArrange.aspx.cs"
    Inherits="LabMS.Web.UpdateCouArrange" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>课程调整</title>
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../style/ie7.css" />
    <![endif]-->
</head>
<body class="mainBody">
    <form id="form1" runat="server">
        <div class="main">
            <div id="pageInfo" class="clearfix">
                <div class="title">
                    <label>课程调整</label>
                </div>
            </div>
        </div>
        <div style="padding: 5px;" class="main">
            <p>
                <asp:Button ID="DeleteBtn" CssClass="button" runat="server" Text="删除" OnClick="Delete_OnClick" /></p>
            <table cellpadding="2" cellspacing="0" border="0">
                <tr>
                    <td>
                        学年：
                    </td>
                    <td>
                        <asp:DropDownList ID="YearDDL" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_OnSelectIndexChange">
                        </asp:DropDownList></td>
                    <td>
                        学期：
                    </td>
                    <td>
                        <asp:DropDownList ID="TermDDL" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_OnSelectIndexChange">
                            <asp:ListItem Text="春季学期" Value="1"></asp:ListItem>
                            <asp:ListItem Text="秋季学期" Value="2"></asp:ListItem>
                        </asp:DropDownList></td>
                    <td>
                        课程：
                    </td>
                    <td>
                        <asp:DropDownList ID="CourseDDL" runat="server" DataTextField="Course_Name" DataValueField="ID"
                            AutoPostBack="true" OnSelectedIndexChanged="CourseDDL_OnSelectIndexChange">
                        </asp:DropDownList></td>
                    <td>
                        周次：
                    </td>
                    <td>
                        <asp:DropDownList ID="WeekDDL" runat="server">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td>
                        星期：
                    </td>
                    <td>
                        <asp:DropDownList ID="WeekDayDDL" runat="server">
                            <asp:ListItem Text="--全部星期--" Value="0">
                            </asp:ListItem>
                            <asp:ListItem Text="星期一" Value="1">
                            </asp:ListItem>
                            <asp:ListItem Text="星期二" Value="2">
                            </asp:ListItem>
                            <asp:ListItem Text="星期三" Value="3">
                            </asp:ListItem>
                            <asp:ListItem Text="星期四" Value="4">
                            </asp:ListItem>
                            <asp:ListItem Text="星期五" Value="5">
                            </asp:ListItem>
                            <asp:ListItem Text="星期六" Value="6">
                            </asp:ListItem>
                            <asp:ListItem Text="星期日" Value="7">
                            </asp:ListItem>
                        </asp:DropDownList></td>
                    <td>
                        地点：
                    </td>
                    <td>
                        <asp:TextBox ID="LocationBTX" runat="server"></asp:TextBox></td>
                    <td>
                        教师：
                    </td>
                    <td>
                        <asp:TextBox ID="TeacherTBX" runat="server"></asp:TextBox></td>
                    <td>
                    </td>
                    <td>
                        <asp:Button ID="SearchBtn" CssClass="button" runat="server" Text="搜索" OnClick="Search_OnClick" /></td>
                </tr>
            </table>
            </div>
            <div class="main">
            <asp:GridView ID="ArrangementGridView" CssClass="infoTable" runat="server" DataKeyNames="LabName"
                Width="100%" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" OnPageIndexChanging="ArrangementGridView_OnPageChange">
                <Columns>
                    <asp:TemplateField ItemStyle-CssClass="checkBox">
                        <HeaderTemplate>
                            <asp:CheckBox ID="CBAll" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chk" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="CourseName" HeaderText="课程" />
                    <asp:BoundField DataField="Week" HeaderText="周次" />
                    <asp:BoundField DataField="WeekDay" HeaderText="星期" />
                    <asp:BoundField DataField="Lession" HeaderText="节次(大节)" />
                    <asp:BoundField DataField="ClassName" HeaderText="班级" />
                    <asp:BoundField DataField="TeacherName" HeaderText="教师" />
                    <asp:BoundField DataField="LocationName" HeaderText="地点" />
                    <asp:TemplateField>
                        <HeaderTemplate>
                            调整
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Button ID="ReSet" runat="server" Text="调整" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "LabName")%>'
                                CommandName="ReSet" OnCommand="ReSet_OnCommand" CssClass="button" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    暂无信息
                </EmptyDataTemplate>
                <HeaderStyle CssClass="header" />
            </asp:GridView>
            <table id="arrtable" runat="server" visible="false">
                <tr>
                    <td>
                        <asp:Button ID="SaveBtn" CssClass="button" runat="server" Text="保存" OnClick="Save_OnClick" />
                        <asp:Button ID="ConcelBtn" CssClass="button" runat="server" Text="取消" OnClick="Concel_OnClick" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    上课地点
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                实验室：
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="LabDDL" runat="server" DataTextField="Lab_Name" AutoPostBack="true"
                                                    DataValueField="ID" OnSelectedIndexChanged="LabDDL_OnSelectIndexChanged">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                房间：
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="HouseDDL" runat="server" DataTextField="Address" DataValueField="ID">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    授课教师：
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                教师名称：
                                            </td>
                                            <td>
                                                <input id="AddTeaBtn" class="button" type="button" value="添加教师" onclick="OpenEditWin('../CommonPage/TeacherList.aspx',500,400)" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                已选教师：
                                            </td>
                                            <td>
                                                <div id="teacherlist" runat="server">
                                                </div>
                                                <input id="tblistEmpty" style="display: none" value="1" runat="server" type="text" />
                                                <input id="tblistStudents" style="display: none" value="" runat="server" type="text" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    实验者对象：
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                班级名称：
                                            </td>
                                            <td>
                                                <input id="AddClassBtn" class="button" type="button" value="添加班级" onclick="OpenEditWin2('../CommonPage/ClassList2.aspx?ID=<%=IDUniq %>',500,400)" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                已选班级：
                                            </td>
                                            <td>
                                                <div id="classlist" runat="server">
                                                </div>
                                                <input id="tblistEmpty2" style="display: none" value="1" runat="server" type="text" />
                                                <input id="tblistStudents2" style="display: none" value="" runat="server" type="text" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    实验时间：
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                周次
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="WeekSelectDDL" runat="server">
                                                </asp:DropDownList>
                                            </td>
                                            <td>
                                                <asp:Label ID="lbDayAndClass" CssClass="cbList" runat="server" Text="Label"></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <asp:TextBox ID="tb_StudentIDs" Style="display: none" runat="server"></asp:TextBox>
        <asp:TextBox ID="tboldcourse" Style="display: none" Text="" runat="server"></asp:TextBox>
        <input id="tb_StudentNames" style="display: none" runat="server" type="text" />
        <input id="tb_StudentNames2" style="display: none" runat="server" type="text" />
        <input id="tb_StudentIDs2" style="display: none" runat="server" type="text" />
        <asp:HiddenField ID="IDHF" runat="server" Value="0" />
    </form>
    <%--<input id="tb_StudentIDs" style=""  runat="server" type="text" />--%>

    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.tooltip.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.bgiframe.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.validate.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.json-1.3.min.js"></script>

    <script type="text/javascript" src="../js/site.js"></script>

    <script type="text/javascript">
        $("#ArrangementGridView > tbody > tr:even").not(":first").addClass("even");
        $("#ArrangementGridView > tbody > tr").not(":first")
            .hover(
                function(){
                    $(this).addClass("hover");
                },
                function(){
                    $(this).removeClass("hover");
            });
    
     //课程表点击事件
    $("#lbDayAndClass input[type='checkbox']").click( 
        function () 
        { 
            $("#lbDayAndClass input[type='checkbox']").attr("checked", false);
            $(this).attr("checked", true);
        }
    ); 
    
    /* 全选 */
    $("#ArrangementGridView > tbody > tr:first :checkbox").click(function(){
        if ($(this).attr("checked")){
            $("#ArrangementGridView :checkbox").attr("checked", "checked");
            cbChanged();
        } else{
            $("#ArrangementGridView :checkbox").attr("checked", "");
            cbChanged();
        }
    });
    
     /* Checkbox事件 */
    $("#ArrangementGridView :checkbox").not(":first").click(cbChanged);
    
    cbChanged();
    
    /* 检测Checkbox的选择状态，更改button的disabled属性 */
        function cbChanged(){
            var hasChecked = false;
            var allChecked = true;
            $("#ArrangementGridView :checkbox").not(":first").each(function(index, domEle){
                var curChecked = $(domEle).attr("checked");
                if (!hasChecked && curChecked){
                    hasChecked = true;
                }

                allChecked &= curChecked;
            });

            if (hasChecked){
                $("#DeleteBtn").attr("disabled", "");
            } else {
                $("#DeleteBtn").attr("disabled", "disabled");
            }

            if (allChecked){
                $("#ArrangementGridView :checkbox").filter(":first").attr("checked", "checked");
            } else {
                $("#ArrangementGridView :checkbox").filter(":first").attr("checked", "");
            }
        }
        
         $(document).ready(function(){
         $("#lbDayAndClass input[type='checkbox']").attr("checked", false);
         if($("#tboldcourse").val()!="")
         {
             $("#"+$("#tboldcourse").val()).attr("checked", true);
         }
        if($("#tblistStudents").val()!="")
        $("#teacherlist").html($("#tblistStudents").val());
         $("#teacherlist  a").css("cursor","pointer"); 
              
               
              $("#teacherlist  a").click( function () 
                                                     { 
                                                        var strsID = $(this).parent().parent().children().html();
                                                        var listID = $("#tb_StudentIDs").val().split(',');
                                                        var value = "";
                                                          for(var i=0; i<listID.length; ++i)
                                                         {
                                                             if(listID[i] != strsID)
                                                            {
                                                                  if(value=="")
                                                                 {
                                                                    value = listID[i];
                                                                 } 
                                                                 else
                                                                {
                                                                    value += "," + listID[i];
                                                                }  
                                                             }
                                                               
                                                         } 
                                                        $("#tb_StudentIDs").val(value); 
                                                        $(this).parent().parent().remove();
                                                        if($("#tb_StudentIDs").val()=="")
                                                        {
                                                            $("#teacherlist").html("");
                                                            $("#tblistEmpty").val(1); 
                                                        }
                                                        $("#tblistStudents").val($("#teacherlist").html()); 
                                                 }); 
                                                 
                                                 
        if($("#tblistStudents2").val()!="")
        $("#classlist").html($("#tblistStudents2").val());
         $("#classlist  a").css("cursor","pointer"); 
              
               
              $("#classlist  a").click( function () 
                                                     { 
                                                        var strsID = $(this).parent().parent().children().html();
                                                        var listID = $("#tb_StudentIDs2").val().split(',');
                                                        var value = "";
                                                          for(var i=0; i<listID.length; ++i)
                                                         {
                                                             if(listID[i] != strsID)
                                                            {
                                                                  if(value=="")
                                                                 {
                                                                    value = listID[i];
                                                                 } 
                                                                 else
                                                                {
                                                                    value += "," + listID[i];
                                                                }  
                                                             }
                                                               
                                                         } 
                                                        $("#tb_StudentIDs2").val(value); 
                                                        $(this).parent().parent().remove();
                                                        if($("#tb_StudentIDs2").val()=="")
                                                        {
                                                            $("#classlist").html("");
                                                            $("#tblistEmpty2").val(1); 
                                                        }
                                                        $("#tblistStudents2").val($("#classlist").html()); 
                                                 }); 
    });
      
     function OpenEditWin(frmWin,width,height) 
      {       
           var me; 
           me = window;  
           var ret = window.showModalDialog (frmWin,'newwindow','height='+height+',width='+width+',top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
          if (ret != null) 
           { 
                var strTable = ""; 
                var listEmpty = $("#tblistEmpty").val();
                if(listEmpty=="1")
                {  
                    var HTML = "<table id='studenlist' class='infoTable' border='1' style='border-collapse: collapse;'>";
                    HTML += "<thead>";
                    HTML += "<tr class='header'>";
                    HTML += "<th style='display:none'>";
                    HTML += "ID";
                    HTML += "</th>";

                    HTML += "<th>";
                    HTML += "教师编号";
                    HTML += "</th>";

                    HTML += "<th>";
                    HTML += "教师姓名";
                    HTML += "</th>";
                    HTML += "<th>";
                    HTML += "删除";
                    HTML += "</th>"; 
                    HTML += "</tr>";
                    HTML += "</thead>"; 
                    strTable +=   HTML;
                   $("#tblistEmpty").val(0); 
                }
                
                var HTML2 = ""; 
                var value=$("#tb_StudentIDs").val();
                var value2=$("#tb_StudentNames").val();
                 for(var j=0; j<1; ++j)
                {
                    if(value!=""){
                          $("#teacherlist").children().children("tbody").html("");
                          }
                        HTML2 += "<tr>"; 
                        HTML2 += "<td style='display:none'>"; 
                        value=ret[2];
                        value2=ret[1]; 
                        HTML2 += ret[2]; 
                        HTML2 += "</td>"; 
                        HTML2 += "<td>"; 
                        HTML2 += ret[0]; 
                        HTML2 += "</td>";
                        HTML2 += "<td>"; 
                        HTML2 += ret[1]; 
                        HTML2 += "</td>";
                        HTML2 += "<td>"; 
                        HTML2 += "<a>删除</a>"; 
                        HTML2 += "</td>";
                        HTML2 += "</tr>";  
                        strTable +=   HTML2; 
                        HTML2 = "";       
                }
                $("#tb_StudentIDs").val(value); 
                 $("#tb_StudentNames").val(value2);
                if(listEmpty=="1")
                {  
                    var HTML3 = "</table>";
                    strTable +=   HTML3;    
                    $("#teacherlist").append(strTable); 
                }
                else
                {
                    $("#teacherlist").children().children("tbody").append(strTable);
                }
                $("#tblistStudents").val($("#teacherlist").html());
                
               $("#teacherlist  a").css("cursor","pointer"); 
              
               
              $("#teacherlist  a").click( function () 
                                                     { 
                                                        var strsID = $(this).parent().parent().children().html();
                                                        var listID = $("#tb_StudentIDs").val().split(',');
                                                        var value = "";
                                                          for(var i=0; i<listID.length; ++i)
                                                         {
                                                             if(listID[i] != strsID)
                                                            {
                                                                  if(value=="")
                                                                 {
                                                                    value = listID[i];
                                                                 } 
                                                                 else
                                                                {
                                                                    value += "," + listID[i];
                                                                }  
                                                             }
                                                               
                                                         } 
                                                        $("#tb_StudentIDs").val(value); 
                                                        $(this).parent().parent().remove();
                                                        if($("#tb_StudentIDs").val()=="")
                                                        {
                                                            $("#teacherlist").html("");
                                                            $("#tblistEmpty").val(1); 
                                                        }
                                                           $("#tblistStudents").val($("#teacherlist").html()); 
                                                 }); 
              
           }  
      } 
      
      function OpenEditWin2(frmWin,width,height) 
      {       
           var me; 
           me = window;  
           var ret = window.showModalDialog (frmWin,'newwindow','height='+height+',width='+width+',top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
          var obj =  document.getElementById("tblistEmpty2");
          if (ret != null) 
           { 
                var strTable = ""; 
                var listEmpty = obj.value;
                if(listEmpty=="1")
                {  
                    var HTML = "<table id='studenlist2' class='infoTable' border='1' style='border-collapse: collapse;'>";
                    HTML += "<thead>";
                    HTML += "<tr class='header'>";
                    HTML += "<th style='display:none'>";
                    HTML += "ID";
                    HTML += "</th>";
                    HTML += "<th>";
                    HTML += "班级编号";
                    HTML += "</th>";

                    HTML += "<th>";
                    HTML += "班级姓名";
                    HTML += "</th>";
                     HTML += "<th>";
                    HTML += "专业";
                    HTML += "</th>";
                     HTML += "<th>";
                    HTML += "班级人数";
                    HTML += "</th>";
                    HTML += "<th>";
                    HTML += "删除";
                    HTML += "</th>"; 
                    HTML += "</tr>";
                    HTML += "</thead>"; 
                    strTable +=   HTML;
                   $("#tblistEmpty2").val(0); 
                }
                
                var HTML2 = ""; 
                var value=$("#tb_StudentIDs2").val();
                var value2=$("#tb_StudentNames2").val();
                var listID = value.split(',');
                 for(var j=0; j<ret.Items.length; ++j)
                {
                    var item = ret.Items[j];
                   if(value!=""){
                        var HasID = false;
                        for(var i=0; i<listID.length; ++i)
                        {
                            if(listID[i] == ret[2])
                           {
                            HasID = true; 
                            }  
                        } 
                        if(!HasID)
                        { 
                            HTML2 += "<tr>"; 
                            HTML2 += "<td style='display:none'>"; 
                            value=value+","+item.ID; 
                            value2=value2+","+item.Name; 
                            $("#tb_StudentIDs2").val(value);  
                            HTML2 += item.ID; 
                            HTML2 += "</td>"; 
                            HTML2 += "<td>"; 
                            HTML2 += item.Code; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Name; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Pro; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Num; 
                            HTML2 += "</td>";
                           HTML2 += "<td>"; 
                            HTML2 += "<a>删除</a>"; 
                            HTML2 += "</td>"; 
                            HTML2 += "</tr>";  
                            strTable +=   HTML2; 
                           HTML2 = ""; 
                        }   
                    }else
                    {
                        HTML2 += "<tr>"; 
                        HTML2 += "<td style='display:none'>"; 
                        value=item.ID;
                        value2=item.Name; 
                        HTML2 += item.ID; 
                        HTML2 += "</td>"; 
                       HTML2 += "<td>"; 
                            HTML2 += item.Code; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Name; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Pro; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Num; 
                            HTML2 += "</td>";
                        HTML2 += "<td>"; 
                        HTML2 += "<a>删除</a>"; 
                        HTML2 += "</td>";
                        HTML2 += "</tr>";  
                        strTable +=   HTML2; 
                        HTML2 = ""; 
                    }       
                }
                $("#tb_StudentIDs2").val(value); 
                $("#tb_StudentNames2").val(value2); 
                if(listEmpty=="1")
                {  
                    var HTML3 = "</table>";
                    strTable +=   HTML3;    
                    $("#classlist").append(strTable); 
                }
                else
                {
                    $("#classlist").children().children("tbody").append(strTable);
                }
                $("#tblistStudents2").val($("#classlist").html());
                
               $("#classlist  a").css("cursor","pointer"); 
              
               
              $("#classlist  a").click( function () 
                                                     { 
                                                        var strsID = $(this).parent().parent().children().html();
                                                        var listID = $("#tb_StudentIDs2").val().split(',');
                                                        var value = "";
                                                          for(var i=0; i<listID.length; ++i)
                                                         {
                                                             if(listID[i] != strsID)
                                                            {
                                                                  if(value=="")
                                                                 {
                                                                    value = listID[i];
                                                                 } 
                                                                 else
                                                                {
                                                                    value += "," + listID[i];
                                                                }  
                                                             }
                                                               
                                                         } 
                                                        $("#tb_StudentIDs2").val(value); 
                                                        $(this).parent().parent().remove();
                                                        if($("#tb_StudentIDs2").val()=="")
                                                        {
                                                            $("#classlist").html("");
                                                            $("#tblistEmpty2").val(1); 
                                                        }
                                                           $("#tblistStudents2").val($("#classlist").html()); 
                                                 }); 
              
           }  
      } 
    </script>

</body>
</html>
